﻿using System.Collections.Generic;
using System.Linq;
using Best.SmartCms.Dao.Common;
using Best.SmartCms.Domain;
using Best.SmartCms.Domain.Common;

namespace Best.SmartCms.Dao
{
    public class AttachmentDao : BaseDao<Attachment>, ICommonDao
    {
        private readonly MySqlDbContext _db;

        public AttachmentDao(MySqlDbContext dbContext) : base(dbContext)
        {
            _db = dbContext;
        }


        public List<Attachment> FindBySourceId(long id,int sourceType)
        {
            return _db.AttachmentSet.Where(p => p.SourceId == id && p.SourceType== sourceType).ToList();
        }

        public Attachment FindByOssKey(string id)
        {
            return _db.AttachmentSet.FirstOrDefault(p => p.OssKey == id);
        }
    }
}
